package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: SetmealController
 * Package: com.sky.controller.admin
 * Description:套餐
 *
 * @Author: Zhang Peiyuan
 * @Create: 2024-12-19-14:42
 * @Version: v1.0
 */
@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Resource
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping()
    public Result saveSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.saveSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 分页查询套餐
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> querySetmealPage(SetmealPageQueryDTO setmealPageQueryDTO) {
        return Result.success(setmealService.querySetmealPage(setmealPageQueryDTO));
    }

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        setmealService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 用于修改套餐中的参数回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SetmealVO> querySetmeal(@PathVariable Long id) {
        return Result.success(setmealService.querySetmeal(id));
    }

    /**
     * 修改套餐
     * @param setmealDTO
     * @return
     */
    @PutMapping()
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result updateSetmealStatus(@PathVariable Integer status, @RequestParam Long id) {
        setmealService.updateSetmealStatus(status, id);
        return Result.success();
    }
}
